package com.aishare.qicaitaoke.mvp.presenter;

import android.content.Context;

import com.aishare.qicaitaoke.mvp.contract.LoginContract;
import com.aishare.qicaitaoke.mvp.model.LoginModel;
import com.aishare.qicaitaoke.mvp.model.bean.LoginBean;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 作者luwenming
 * 时间2018/1/31
 */

public class LoginPresenter implements LoginContract.Presenter{

    private LoginContract.View mView;
    private Context context;
    private LoginModel loginModel;

    public LoginPresenter(Context context,LoginContract.View view){
        mView = view;
        this.context = context;
    }

    @Override
    public void start() {
        requestData();
    }

    private void requestData(){
        if(loginModel==null){
            loginModel = new LoginModel();
        }
        loginModel.loadData().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Observer<LoginBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(LoginBean loginBean) {
                    mView.updateUI();
            }
        });

    }
}
